<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - ged.info - gil/iterator_from_2d.hpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LTP GCOV extension - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
        <tr>
          <td class="headerItem" width="20%">Current&nbsp;view:</td>
          <td class="headerValue" width="80%" colspan=4><a href="../index.html">directory</a> - <a href="index.html">gil</a> - iterator_from_2d.hpp</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Test:</td>
          <td class="headerValue" width="80%" colspan=4>ged.info</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Date:</td>
          <td class="headerValue" width="20%">2009-06-09</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Instrumented&nbsp;lines:</td>
          <td class="headerValue" width="20%">15</td>
        </tr>
        <tr>
          <td class="headerItem" width="20%">Code&nbsp;covered:</td>
          <td class="headerValue" width="20%">86.7 %</td>
          <td width="20%"></td>
          <td class="headerItem" width="20%">Executed&nbsp;lines:</td>
          <td class="headerValue" width="20%">13</td>
        </tr>
        </table>
      </td>
    </tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td><pre class="source">
<span class="lineNum">       1 </span>                : /*
<span class="lineNum">       2 </span>                :     Copyright 2005-2007 Adobe Systems Incorporated
<span class="lineNum">       3 </span>                :    
<span class="lineNum">       4 </span>                :     Use, modification and distribution are subject to the Boost Software License,
<span class="lineNum">       5 </span>                :     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
<span class="lineNum">       6 </span>                :     http://www.boost.org/LICENSE_1_0.txt).
<span class="lineNum">       7 </span>                : 
<span class="lineNum">       8 </span>                :     See http://opensource.adobe.com/gil for most recent version including documentation.
<span class="lineNum">       9 </span>                : */
<span class="lineNum">      10 </span>                : /*************************************************************************************************/
<span class="lineNum">      11 </span>                : 
<span class="lineNum">      12 </span>                : #ifndef GIL_ITERATOR_FROM_2D_H
<span class="lineNum">      13 </span>                : #define GIL_ITERATOR_FROM_2D_H
<span class="lineNum">      14 </span>                : 
<span class="lineNum">      15 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      16 </span>                : /// \file               
<span class="lineNum">      17 </span>                : /// \brief pixel step iterator, pixel image iterator and pixel dereference iterator
<span class="lineNum">      18 </span>                : /// \author Lubomir Bourdev and Hailin Jin \n
<span class="lineNum">      19 </span>                : ///         Adobe Systems Incorporated
<span class="lineNum">      20 </span>                : /// \date   2005-2007 \n Last updated on September 18, 2007
<span class="lineNum">      21 </span>                : ///
<span class="lineNum">      22 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      23 </span>                : 
<span class="lineNum">      24 </span>                : #include &lt;cassert&gt;
<span class="lineNum">      25 </span>                : #include &lt;boost/iterator/iterator_facade.hpp&gt;
<span class="lineNum">      26 </span>                : #include &quot;gil_concept.hpp&quot;
<span class="lineNum">      27 </span>                : #include &quot;gil_config.hpp&quot;
<span class="lineNum">      28 </span>                : #include &quot;pixel_iterator.hpp&quot;
<span class="lineNum">      29 </span>                : #include &quot;locator.hpp&quot;
<span class="lineNum">      30 </span>                : 
<span class="lineNum">      31 </span>                : namespace boost { namespace gil {
<span class="lineNum">      32 </span>                : 
<span class="lineNum">      33 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      34 </span>                : ///                 
<span class="lineNum">      35 </span>                : ///                 ITERATOR FROM 2D ADAPTOR
<span class="lineNum">      36 </span>                : ///
<span class="lineNum">      37 </span>                : ////////////////////////////////////////////////////////////////////////////////////////
<span class="lineNum">      38 </span>                : 
<span class="lineNum">      39 </span>                : 
<span class="lineNum">      40 </span>                : /// \defgroup PixelIteratorModelFromLocator iterator_from_2d
<span class="lineNum">      41 </span>                : /// \ingroup PixelIteratorModel
<span class="lineNum">      42 </span>                : /// \brief An iterator over two-dimensional locator. Useful for iterating over the pixels of an image view. Models PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept
<span class="lineNum">      43 </span>                : 
<span class="lineNum">      44 </span>                : 
<span class="lineNum">      45 </span>                : /// \ingroup PixelIteratorModelFromLocator PixelBasedModel
<span class="lineNum">      46 </span>                : /// \brief Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept
<span class="lineNum">      47 </span>                : ///
<span class="lineNum">      48 </span>                : /// Pixels are traversed from the top to the bottom row and from the left to the right 
<span class="lineNum">      49 </span>                : /// within each row
<span class="lineNum">      50 </span>                : 
<span class="lineNum">      51 </span>                : template &lt;typename Loc2&gt;    // Models PixelLocatorConcept
<span class="lineNum">      52 </span>                : class iterator_from_2d : public iterator_facade&lt;iterator_from_2d&lt;Loc2&gt;,
<span class="lineNum">      53 </span>                :                                                 typename Loc2::value_type,
<span class="lineNum">      54 </span>                :                                                 random_access_traversal_tag,
<span class="lineNum">      55 </span>                :                                                 typename Loc2::reference,
<span class="lineNum">      56 </span><span class="lineCov">             28 :                                                 typename Loc2::coord_t&gt; {</span>
<span class="lineNum">      57 </span>                :     GIL_CLASS_REQUIRE(Loc2, boost::gil, PixelLocatorConcept)
<span class="lineNum">      58 </span>                : public:
<span class="lineNum">      59 </span>                :     typedef iterator_facade&lt;iterator_from_2d&lt;Loc2&gt;,
<span class="lineNum">      60 </span>                :                             typename Loc2::value_type,
<span class="lineNum">      61 </span>                :                             random_access_traversal_tag,
<span class="lineNum">      62 </span>                :                             typename Loc2::reference,
<span class="lineNum">      63 </span>                :                             typename Loc2::coord_t&gt; parent_t;
<span class="lineNum">      64 </span>                :     typedef typename parent_t::reference       reference;
<span class="lineNum">      65 </span>                :     typedef typename parent_t::difference_type difference_type;
<span class="lineNum">      66 </span>                :     typedef typename Loc2::x_iterator          x_iterator;
<span class="lineNum">      67 </span>                :     typedef typename Loc2::point_t             point_t;
<span class="lineNum">      68 </span>                : 
<span class="lineNum">      69 </span>                :     std::ptrdiff_t width()         const { return _width; }            // number of pixels per image row
<span class="lineNum">      70 </span>                :     std::ptrdiff_t x_pos()         const { return _coords.x; }         // current x position
<span class="lineNum">      71 </span>                :     std::ptrdiff_t y_pos()         const { return _coords.y; }         // current y position
<span class="lineNum">      72 </span>                : 
<span class="lineNum">      73 </span>                :     /// For some reason operator[] provided by iterator_adaptor returns a custom class that is convertible to reference
<span class="lineNum">      74 </span>                :     /// We require our own reference because it is registered in iterator_traits
<span class="lineNum">      75 </span>                :     reference operator[](difference_type d) const { return *(*this+d); }
<span class="lineNum">      76 </span>                : 
<span class="lineNum">      77 </span>                :     bool            is_1d_traversable() const { return _p.is_1d_traversable(width()); }   // is there no gap at the end of each row?
<span class="lineNum">      78 </span><span class="lineCov">             14 :     x_iterator&amp;     x()                   { return _p.x(); }</span>
<span class="lineNum">      79 </span>                : 
<span class="lineNum">      80 </span>                :     iterator_from_2d(){}
<span class="lineNum">      81 </span><span class="lineCov">             14 :     iterator_from_2d(const Loc2&amp; p, std::ptrdiff_t width, std::ptrdiff_t x=0, std::ptrdiff_t y=0) : _coords(x,y), _width(width), _p(p) {}</span>
<span class="lineNum">      82 </span><span class="lineCov">             14 :     iterator_from_2d(const iterator_from_2d&amp; pit) : _coords(pit._coords), _width(pit._width), _p(pit._p) {}</span>
<span class="lineNum">      83 </span>                :     template &lt;typename Loc&gt; iterator_from_2d(const iterator_from_2d&lt;Loc&gt;&amp; pit) : _coords(pit._coords), _width(pit._width), _p(pit._p) {}
<span class="lineNum">      84 </span>                : 
<span class="lineNum">      85 </span>                : private:
<span class="lineNum">      86 </span>                :     template &lt;typename Loc&gt; friend class iterator_from_2d;
<span class="lineNum">      87 </span>                :     friend class boost::iterator_core_access;
<span class="lineNum">      88 </span>                :     reference dereference() const { return *_p; }
<span class="lineNum">      89 </span>                :     void increment() {
<span class="lineNum">      90 </span>                :         ++_coords.x;
<span class="lineNum">      91 </span>                :         ++_p.x();
<span class="lineNum">      92 </span>                :         if (_coords.x&gt;=_width) {
<span class="lineNum">      93 </span>                :             _coords.x=0;
<span class="lineNum">      94 </span>                :             ++_coords.y;
<span class="lineNum">      95 </span>                :             _p+=point_t(-_width,1);
<span class="lineNum">      96 </span>                :         }           
<span class="lineNum">      97 </span>                :     }
<span class="lineNum">      98 </span>                :     void decrement() {
<span class="lineNum">      99 </span>                :         --_coords.x;
<span class="lineNum">     100 </span>                :         --_p.x();
<span class="lineNum">     101 </span>                :         if (_coords.x&lt;0) {
<span class="lineNum">     102 </span>                :             _coords.x=_width-1;
<span class="lineNum">     103 </span>                :             --_coords.y;
<span class="lineNum">     104 </span>                :             _p+=point_t(_width,-1);
<span class="lineNum">     105 </span>                :         }
<span class="lineNum">     106 </span>                :     }
<span class="lineNum">     107 </span>                : 
<span class="lineNum">     108 </span><span class="lineCov">              7 :     GIL_FORCEINLINE void advance(difference_type d) {  </span>
<span class="lineNum">     109 </span><span class="lineCov">              7 :         if (_width==0) return;  // unfortunately we need to check for that. Default-constructed images have width of 0 and the code below will throw if executed.</span>
<span class="lineNum">     110 </span><span class="lineCov">              7 :         point_t delta;</span>
<span class="lineNum">     111 </span><span class="lineCov">              7 :         if (_coords.x+d&gt;=0) {  // not going back to a previous row?</span>
<span class="lineNum">     112 </span><span class="lineCov">              7 :             delta.x=(_coords.x+(std::ptrdiff_t)d)%_width - _coords.x;</span>
<span class="lineNum">     113 </span><span class="lineCov">              7 :             delta.y=(_coords.x+(std::ptrdiff_t)d)/_width;</span>
<span class="lineNum">     114 </span>                :         } else {
<span class="lineNum">     115 </span><span class="lineNoCov">              0 :             delta.x=(_coords.x+(std::ptrdiff_t)d*(1-_width))%_width -_coords.x;</span>
<span class="lineNum">     116 </span><span class="lineNoCov">              0 :             delta.y=-(_width-_coords.x-(std::ptrdiff_t)d-1)/_width;</span>
<span class="lineNum">     117 </span>                :         }   
<span class="lineNum">     118 </span><span class="lineCov">              7 :         _p+=delta;</span>
<span class="lineNum">     119 </span><span class="lineCov">              7 :         _coords.x+=delta.x;</span>
<span class="lineNum">     120 </span><span class="lineCov">              7 :         _coords.y+=delta.y;</span>
<span class="lineNum">     121 </span>                :     }
<span class="lineNum">     122 </span>                : 
<span class="lineNum">     123 </span>                :     difference_type distance_to(const iterator_from_2d&amp; it) const { 
<span class="lineNum">     124 </span>                :         if (_width==0) return 0;
<span class="lineNum">     125 </span>                :         return (it.y_pos()-_coords.y)*_width + (it.x_pos()-_coords.x);
<span class="lineNum">     126 </span>                :     }
<span class="lineNum">     127 </span>                : 
<span class="lineNum">     128 </span>                :     bool equal(const iterator_from_2d&amp; it) const {
<span class="lineNum">     129 </span>                :         assert(_width==it.width());     // they must belong to the same image
<span class="lineNum">     130 </span>                :         return _coords==it._coords &amp;&amp; _p==it._p;
<span class="lineNum">     131 </span>                :     }
<span class="lineNum">     132 </span>                : 
<span class="lineNum">     133 </span>                :     point2&lt;std::ptrdiff_t&gt; _coords;
<span class="lineNum">     134 </span>                :     std::ptrdiff_t _width;
<span class="lineNum">     135 </span>                :     Loc2 _p;
<span class="lineNum">     136 </span>                : };
<span class="lineNum">     137 </span>                : 
<span class="lineNum">     138 </span>                : template &lt;typename Loc&gt; // Models PixelLocatorConcept
<span class="lineNum">     139 </span>                : struct const_iterator_type&lt;iterator_from_2d&lt;Loc&gt; &gt; {
<span class="lineNum">     140 </span>                :     typedef iterator_from_2d&lt;typename Loc::const_t&gt; type;
<span class="lineNum">     141 </span>                : };
<span class="lineNum">     142 </span>                : 
<span class="lineNum">     143 </span>                : template &lt;typename Loc&gt; // Models PixelLocatorConcept
<span class="lineNum">     144 </span>                : struct iterator_is_mutable&lt;iterator_from_2d&lt;Loc&gt; &gt; : public iterator_is_mutable&lt;typename Loc::x_iterator&gt; {};
<span class="lineNum">     145 </span>                : 
<span class="lineNum">     146 </span>                : 
<span class="lineNum">     147 </span>                : /////////////////////////////
<span class="lineNum">     148 </span>                : //  HasDynamicXStepTypeConcept
<span class="lineNum">     149 </span>                : /////////////////////////////
<span class="lineNum">     150 </span>                : 
<span class="lineNum">     151 </span>                : template &lt;typename Loc&gt;
<span class="lineNum">     152 </span>                : struct dynamic_x_step_type&lt;iterator_from_2d&lt;Loc&gt; &gt; {
<span class="lineNum">     153 </span>                :     typedef iterator_from_2d&lt;typename dynamic_x_step_type&lt;Loc&gt;::type&gt;  type;
<span class="lineNum">     154 </span>                : };
<span class="lineNum">     155 </span>                : 
<span class="lineNum">     156 </span>                : 
<span class="lineNum">     157 </span>                : /////////////////////////////
<span class="lineNum">     158 </span>                : //  PixelBasedConcept
<span class="lineNum">     159 </span>                : /////////////////////////////
<span class="lineNum">     160 </span>                : 
<span class="lineNum">     161 </span>                : template &lt;typename Loc&gt; // Models PixelLocatorConcept
<span class="lineNum">     162 </span>                : struct color_space_type&lt;iterator_from_2d&lt;Loc&gt; &gt; : public color_space_type&lt;Loc&gt; {};
<span class="lineNum">     163 </span>                : 
<span class="lineNum">     164 </span>                : template &lt;typename Loc&gt; // Models PixelLocatorConcept
<span class="lineNum">     165 </span>                : struct channel_mapping_type&lt;iterator_from_2d&lt;Loc&gt; &gt; : public channel_mapping_type&lt;Loc&gt; {};
<span class="lineNum">     166 </span>                : 
<span class="lineNum">     167 </span>                : template &lt;typename Loc&gt; // Models PixelLocatorConcept
<span class="lineNum">     168 </span>                : struct is_planar&lt;iterator_from_2d&lt;Loc&gt; &gt; : public is_planar&lt;Loc&gt; {};
<span class="lineNum">     169 </span>                : 
<span class="lineNum">     170 </span>                : template &lt;typename Loc&gt; // Models PixelLocatorConcept
<span class="lineNum">     171 </span>                : struct channel_type&lt;iterator_from_2d&lt;Loc&gt; &gt; : public channel_type&lt;Loc&gt; {};
<span class="lineNum">     172 </span>                : 
<span class="lineNum">     173 </span>                : } }  // namespace boost::gil
<span class="lineNum">     174 </span>                : 
<span class="lineNum">     175 </span>                : #endif
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LTP GCOV extension version 1.6</a></td></tr>
  </table>
  <br>

</body>
</html>
